package com.anmai.crawler1.dao;

import com.anmai.crawler1.entity.CityBean;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


public interface CityDao {
    int deleteByPrimaryKey(Integer id);


    @Insert("insert into city(url,initial,city_name,create_time,update_time) values(#{url},#{initial},#{cityName},#{createTime},#{updateTime})")
    int insert(CityBean record);

    int insertSelective(CityBean record);

    @Select("select * from city where id = #{id}")
    CityBean selectByPrimaryKey(@Param("id") Integer id);

    @Select("select * from city")
    @Results({
            @Result(property = "updateTime", column = "update_time"),

            @Result(property = "createTime", column = "create_time"),

            @Result(property = "cityName", column = "city_name")
    })
    List<CityBean> selectCities();

    int updateByPrimaryKeySelective(CityBean record);


    @Update("update city set status = #{status,jdbcType=INTEGER},lat = #{lat,jdbcType=DOUBLE},lng=#{lng,jdbcType=DOUBLE} where id = #{id,jdbcType=INTEGER}" )
    int updateByPrimaryKey(CityBean record);

    @Select("select count(id) from city where city_name = #{cityName,jdbcType=VARCHAR} and url = #{url,jdbcType=VARCHAR}")
    Integer isExist(CityBean cityBean);

    @Select("select * from city where status = #{status,jdbcType=INTEGER}")
    @Results({
            @Result(property = "updateTime", column = "update_time"),

            @Result(property = "createTime", column = "create_time"),

            @Result(property = "cityName", column = "city_name")
    })
    List<CityBean> findCitiesByStatus(@Param("status") Integer status);


    @Update("update city set status =  #{status,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}")
    Integer updateStatus(CityBean cityBean);


    //查找没有商圈的区域
    @Select("SELECT * from  city WHERE id not in (SELECT city_id FROM area) and status <> -1")
    @Results({
            @Result(property = "updateTime", column = "update_time"),

            @Result(property = "createTime", column = "create_time"),

            @Result(property = "cityId", column = "city_id"),

            @Result(property = "cityName", column = "city_name")

    })
    List<CityBean> findCityNoBussiness();

    /**
     * 获取总记录数
     */
    @Select("SELECT COUNT(id) FROM shop")
    Integer counts();

    /**
     *
     *
     */

//    public void fin


}